import java.io.IOException;
import oracle.jdbc.driver.*;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;

/**
 * Servlet implementation class testServlet
 */
@WebServlet("/testServlet")
public class testServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public testServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	final private static String driverName = "oracle.jdbc.driver.OracleDriver";
	private static String url;
	final private static String server = "127.0.0.1";
	final private static String port = "1521";
	final private static String sid = "XE";
	final private static String username = "objectman";
	final private static String password = "objectman";
	private static Connection connection;
	private static boolean isConnected = false;    
    
	private static boolean connect() throws ClassNotFoundException, SQLException {

	        url = "jdbc:oracle:thin:@" + server + ":" + port + ":" + sid;
	        System.out.println(url);
	        Class.forName(driverName);
	        connection = DriverManager.getConnection(url, username, password);
	        System.out.println("connecting: " + url);
	        if(connection.equals(null))
	            isConnected = false;
	        else
	            isConnected = true;

	    return isConnected;
	}    
    
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
        response.setContentType( "text/html" );  
        PrintWriter out = response.getWriter();  
        out.println( "<html><head>" );  
        out.println( "<title>A Sample Servlet!</title>" );
        out.println( "</head>" );  
        out.println( "<body>" );  
        out.println( "<h1>Hello, World!</h1>" );
        boolean b;
		try {
			b = connect();
			out.println(b);
		} catch (ClassNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
        try {
			out.println("<h2>" + SimpleTransform.Transform() + "</h2>");
		} catch (TransformerConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (TransformerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}  
        out.println( "</body></html>" );  
        out.close();  
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}